package qlsl.androiddesign.view.subview.commonview;

import com.qlsl.androiddesign.kuaiwa.R;

import android.net.Uri;
import android.view.View;
import io.vov.vitamio.MediaPlayer;
import io.vov.vitamio.MediaPlayer.OnErrorListener;
import io.vov.vitamio.MediaPlayer.OnPreparedListener;
import io.vov.vitamio.widget.MediaController;
import io.vov.vitamio.widget.VideoView;
import qlsl.androiddesign.activity.commonactivity.VideoPlayActivity;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 视频播放页<br/>
 * 需要传入的键：url<br/>
 * 传入的值类型： String<br/>
 * 传入的值含义：网络视频地址<br/>
 * 是否必传 ：是
 */
public class VideoPlayView extends FunctionView<VideoPlayActivity> implements OnPreparedListener, OnErrorListener {

	private VideoView videoView;

	public VideoPlayView(VideoPlayActivity activity) {
		super(activity);
		setContentView(R.layout.activity_video_play);
	}

	protected void initView(View view) {
		setTitle("视频播放");
		videoView = findViewById(R.id.videoView);
	}

	protected void initData() {
		playByVitamio();
	}

	protected void initListener() {
		videoView.setOnPreparedListener(this);
		videoView.setOnErrorListener(this);
	}

	public <T> void showData(T... t) {

	}

	public <T> void showNoData(T... t) {

	}

	public void onClick(View view) {

	}

	private void playByVitamio() {
		showProgressBar();
		String url = activity.getIntent().getStringExtra("url");
		videoView.setVideoURI(Uri.parse(url));
		MediaController controller = new MediaController(activity);
		videoView.setMediaController(controller);
		videoView.requestFocus();
	}

	public void onPrepared(MediaPlayer mp) {
		mp.setPlaybackSpeed(1.0f);
		hideProgressBar();
	}

	public boolean onError(MediaPlayer mp, int what, int extra) {
		hideProgressBar();
		return false;
	}

}
